package com.itheima.controller;

import com.itheima.entry.PageResult;
import com.itheima.entry.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author jshstart
 * @creat 2020-11-10 10:45
 */
@RestController
@Api
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;
    @PostMapping("/save")
    public boolean addCheckItem(@RequestBody CheckItem checkItem){
        System.out.println("checkItem = " + checkItem);
        return checkItemService.saveOrUpdate(checkItem);
    }

    @GetMapping("/findAllItem")
    public List<CheckItem> findAllItem(){
//        List<CheckItem> list = checkItemService.list();
//        return list;
        List<CheckItem> list = checkItemService.findAllItem();
        System.out.println("list = " + list);
        return list;
    }
        @PostMapping("queryAllByPage")
    public PageResult findAllPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = checkItemService.findAllByPage(queryPageBean);

        return pageResult;
    }
//    @RequestMapping("/delete")
//    public void delete(@RequestBody Long id){
//        System.out.println("id = " + id);
////        System.out.println("checkItem = " + checkItem.getIs_delete());
////        checkItem.setIs_delete(1);
////        boolean b = checkItemService.updateById(checkItem);
//        boolean b = checkItemService.deleteById(id);
//        System.out.println("b = " + b);
//    }
    @RequestMapping("/delete/{id}")
    public void delete(@PathVariable("id") Long id){
        System.out.println("id = " + id);
        boolean b = checkItemService.deleteById(id);
        System.out.println("b = " + b);
    }
}
